﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace DynamicMVVM.Demo.UI.Converters
{
    public class VisibilityConverter : IValueConverter
    {
        #region Implementation of IValueConverter

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool check = true;
            if (value is bool)
            {
                check = (bool)value;
            }
            else if (value is int)
            {
                check = (int)value != 0;
            }
            else if (value is decimal)
            {
                check = (decimal)value != 0;
            }
            if ((parameter != null) && System.Convert.ToBoolean(parameter))
            {
                check = !check;
            }
            return check ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class InverseConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool check = true;
            if (value is bool)
            {
                check = (bool)value;
            }
            else if (value is int)
            {
                check = (int)value != 0;
            }
            else if (value is decimal)
            {
                check = (decimal)value != 0;
            }
            if ((parameter != null) && System.Convert.ToBoolean(parameter))
            {
                check = !check;
            }
            return check ? Visibility.Collapsed : Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
